

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>O365.drive &mdash; O365  documentation</title>
  

  
  
  
  

  

  
  
    

  

  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" /> 

  
  <script src="../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../index.html" class="icon icon-home"> O365
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../getting_started.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../usage.html">Detailed Usage</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api.html">O365 API</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">O365</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../index.html">Module code</a> &raquo;</li>
        
      <li>O365.drive</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for O365.drive</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>
<span class="kn">from</span> <span class="nn">time</span> <span class="kn">import</span> <span class="n">sleep</span>
<span class="kn">from</span> <span class="nn">urllib.parse</span> <span class="kn">import</span> <span class="n">urlparse</span><span class="p">,</span> <span class="n">quote</span>

<span class="kn">from</span> <span class="nn">dateutil.parser</span> <span class="kn">import</span> <span class="n">parse</span>

<span class="kn">from</span> <span class="nn">.address_book</span> <span class="kn">import</span> <span class="n">Contact</span>
<span class="kn">from</span> <span class="nn">.utils</span> <span class="kn">import</span> <span class="n">ApiComponent</span><span class="p">,</span> <span class="n">Pagination</span><span class="p">,</span> <span class="n">NEXT_LINK_KEYWORD</span><span class="p">,</span> \
    <span class="n">OneDriveWellKnowFolderNames</span>

<span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>

<span class="n">SIZE_THERSHOLD</span> <span class="o">=</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">2</span>  <span class="c1"># 2 MB</span>
<span class="n">UPLOAD_SIZE_LIMIT_SIMPLE</span> <span class="o">=</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">4</span>  <span class="c1"># 4 MB</span>
<span class="n">UPLOAD_SIZE_LIMIT_SESSION</span> <span class="o">=</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">60</span>  <span class="c1"># 60 MB</span>
<span class="n">CHUNK_SIZE_BASE</span> <span class="o">=</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">320</span>  <span class="c1"># 320 Kb</span>

<span class="c1"># 5 MB --&gt; Must be a multiple of CHUNK_SIZE_BASE</span>
<span class="n">DEFAULT_UPLOAD_CHUNK_SIZE</span> <span class="o">=</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">5</span>
<span class="n">ALLOWED_PDF_EXTENSIONS</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;.csv&#39;</span><span class="p">,</span> <span class="s1">&#39;.doc&#39;</span><span class="p">,</span> <span class="s1">&#39;.docx&#39;</span><span class="p">,</span> <span class="s1">&#39;.odp&#39;</span><span class="p">,</span> <span class="s1">&#39;.ods&#39;</span><span class="p">,</span> <span class="s1">&#39;.odt&#39;</span><span class="p">,</span>
                          <span class="s1">&#39;.pot&#39;</span><span class="p">,</span> <span class="s1">&#39;.potm&#39;</span><span class="p">,</span> <span class="s1">&#39;.potx&#39;</span><span class="p">,</span>
                          <span class="s1">&#39;.pps&#39;</span><span class="p">,</span> <span class="s1">&#39;.ppsx&#39;</span><span class="p">,</span> <span class="s1">&#39;.ppsxm&#39;</span><span class="p">,</span> <span class="s1">&#39;.ppt&#39;</span><span class="p">,</span> <span class="s1">&#39;.pptm&#39;</span><span class="p">,</span> <span class="s1">&#39;.pptx&#39;</span><span class="p">,</span>
                          <span class="s1">&#39;.rtf&#39;</span><span class="p">,</span> <span class="s1">&#39;.xls&#39;</span><span class="p">,</span> <span class="s1">&#39;.xlsx&#39;</span><span class="p">}</span>


<div class="viewcode-block" id="DownloadableMixin"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DownloadableMixin">[docs]</a><span class="k">class</span> <span class="nc">DownloadableMixin</span><span class="p">:</span>

<div class="viewcode-block" id="DownloadableMixin.download"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DownloadableMixin.download">[docs]</a>    <span class="k">def</span> <span class="nf">download</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">to_path</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">chunk_size</span><span class="o">=</span><span class="s1">&#39;auto&#39;</span><span class="p">,</span>
                 <span class="n">convert_to_pdf</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Downloads this file to the local drive. Can download the</span>
<span class="sd">        file in chunks with multiple requests to the server.</span>

<span class="sd">        :param to_path: a path to store the downloaded file</span>
<span class="sd">        :type to_path: str or Path</span>
<span class="sd">        :param str name: the name you want the stored file to have.</span>
<span class="sd">        :param int chunk_size: number of bytes to retrieve from</span>
<span class="sd">         each api call to the server. if auto, files bigger than</span>
<span class="sd">         SIZE_THERSHOLD will be chunked (into memory, will be</span>
<span class="sd">         however only 1 request)</span>
<span class="sd">        :param bool convert_to_pdf: will try to download the converted pdf</span>
<span class="sd">         if file extension in ALLOWED_PDF_EXTENSIONS</span>
<span class="sd">        :param RawIOBase output: (optional) an opened io object to write to.</span>
<span class="sd">         if set, the to_path and name will be ignored</span>
<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># TODO: Add download with more than one request (chunk_requests) with</span>
        <span class="c1">#  header &#39;Range&#39;. For example: &#39;Range&#39;: &#39;bytes=0-1024&#39;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">output</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">to_path</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">to_path</span> <span class="o">=</span> <span class="n">Path</span><span class="p">()</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">to_path</span><span class="p">,</span> <span class="n">Path</span><span class="p">):</span>
                    <span class="n">to_path</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">to_path</span><span class="p">)</span>

            <span class="k">if</span> <span class="ow">not</span> <span class="n">to_path</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span>
                <span class="k">raise</span> <span class="ne">FileNotFoundError</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">{}</span><span class="s1"> does not exist&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">to_path</span><span class="p">))</span>

            <span class="k">if</span> <span class="n">name</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">Path</span><span class="p">(</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">suffix</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
                <span class="n">name</span> <span class="o">=</span> <span class="n">name</span> <span class="o">+</span> <span class="n">Path</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">suffix</span>

            <span class="n">name</span> <span class="o">=</span> <span class="n">name</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>
            <span class="n">to_path</span> <span class="o">=</span> <span class="n">to_path</span> <span class="o">/</span> <span class="n">name</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;download&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">chunk_size</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">stream</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="k">elif</span> <span class="n">chunk_size</span> <span class="o">==</span> <span class="s1">&#39;auto&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">size</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">size</span> <span class="o">&gt;</span> <span class="n">SIZE_THERSHOLD</span><span class="p">:</span>
                    <span class="n">stream</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">stream</span> <span class="o">=</span> <span class="kc">False</span>
                <span class="n">chunk_size</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">chunk_size</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
                <span class="n">stream</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Argument chunk_size must be either &#39;auto&#39; &quot;</span>
                                 <span class="s2">&quot;or any integer number representing bytes&quot;</span><span class="p">)</span>

            <span class="n">params</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">if</span> <span class="n">convert_to_pdf</span> <span class="ow">and</span> <span class="n">Path</span><span class="p">(</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">suffix</span> <span class="ow">in</span> <span class="n">ALLOWED_PDF_EXTENSIONS</span><span class="p">:</span>
                <span class="n">params</span><span class="p">[</span><span class="s1">&#39;format&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;pdf&#39;</span>

            <span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">stream</span><span class="o">=</span><span class="n">stream</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">)</span> <span class="k">as</span> <span class="n">response</span><span class="p">:</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
                    <span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Downloading driveitem Request failed: </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                        <span class="n">response</span><span class="o">.</span><span class="n">reason</span><span class="p">))</span>
                    <span class="k">return</span> <span class="kc">False</span>

                <span class="k">def</span> <span class="nf">write_output</span><span class="p">(</span><span class="n">out</span><span class="p">):</span>
                    <span class="k">if</span> <span class="n">stream</span><span class="p">:</span>
                        <span class="k">for</span> <span class="n">chunk</span> <span class="ow">in</span> <span class="n">response</span><span class="o">.</span><span class="n">iter_content</span><span class="p">(</span>
                                <span class="n">chunk_size</span><span class="o">=</span><span class="n">chunk_size</span><span class="p">):</span>
                            <span class="k">if</span> <span class="n">chunk</span><span class="p">:</span>
                                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">chunk</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">content</span><span class="p">)</span>

                <span class="k">if</span> <span class="n">output</span><span class="p">:</span>
                    <span class="n">write_output</span><span class="p">(</span><span class="n">output</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">with</span> <span class="n">to_path</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">mode</span><span class="o">=</span><span class="s1">&#39;wb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">output</span><span class="p">:</span>
                        <span class="n">write_output</span><span class="p">(</span><span class="n">output</span><span class="p">)</span>

        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span>
                <span class="s1">&#39;Error downloading driveitem </span><span class="si">{}</span><span class="s1">. Error: </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                                                   <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)))</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="k">return</span> <span class="kc">True</span></div></div>


<div class="viewcode-block" id="CopyOperation"><a class="viewcode-back" href="../../api/drive.html#O365.drive.CopyOperation">[docs]</a><span class="k">class</span> <span class="nc">CopyOperation</span><span class="p">(</span><span class="n">ApiComponent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; https://github.com/OneDrive/onedrive-api-docs/issues/762 &quot;&quot;&quot;</span>

    <span class="n">_endpoints</span> <span class="o">=</span> <span class="p">{</span>
        <span class="c1"># all prefixed with /drives/{drive_id} on main_resource by default</span>
        <span class="s1">&#39;item&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{id}</span><span class="s1">&#39;</span><span class="p">,</span>
    <span class="p">}</span>

<div class="viewcode-block" id="CopyOperation.__init__"><a class="viewcode-back" href="../../api/drive.html#O365.drive.CopyOperation.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">con</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>

<span class="sd">        :param parent: parent for this operation</span>
<span class="sd">        :type parent: Drive</span>
<span class="sd">        :param Connection con: connection to use if no parent specified</span>
<span class="sd">        :param Protocol protocol: protocol to use if no parent specified</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        :param str main_resource: use this resource instead of parent resource</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        :param str monitor_url:</span>
<span class="sd">        :param str item_id:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">parent</span> <span class="ow">and</span> <span class="n">con</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Need a parent or a connection but not both&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">con</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">con</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">con</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="n">parent</span>  <span class="c1"># parent will be always a DriveItem</span>

        <span class="c1"># Choose the main_resource passed in kwargs over parent main_resource</span>
        <span class="n">main_resource</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span>
            <span class="nb">getattr</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="kc">None</span><span class="p">)</span>

        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">protocol</span><span class="o">=</span><span class="n">parent</span><span class="o">.</span><span class="n">protocol</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;protocol&#39;</span><span class="p">),</span>
            <span class="n">main_resource</span><span class="o">=</span><span class="n">main_resource</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">monitor_url</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;monitor_url&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">item_id</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;item_id&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">monitor_url</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">item_id</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Must provide a valid monitor_url or item_id&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">monitor_url</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">item_id</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s1">&#39;Must provide a valid monitor_url or item_id, but not both&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">item_id</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="o">=</span> <span class="s1">&#39;completed&#39;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">completion_percentage</span> <span class="o">=</span> <span class="mf">100.0</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="o">=</span> <span class="s1">&#39;inProgress&#39;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">completion_percentage</span> <span class="o">=</span> <span class="mf">0.0</span></div>

    <span class="k">def</span> <span class="nf">_request_status</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Checks the api endpoint to check if the async job progress &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">item_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">True</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">monitor_url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;status&#39;</span><span class="p">,</span> <span class="s1">&#39;inProgress&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">completion_percentage</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;percentageComplete&#39;</span><span class="p">),</span>
                                              <span class="mi">0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">item_id</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;resourceId&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">item_id</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>

<div class="viewcode-block" id="CopyOperation.check_status"><a class="viewcode-back" href="../../api/drive.html#O365.drive.CopyOperation.check_status">[docs]</a>    <span class="k">def</span> <span class="nf">check_status</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">delay</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Checks the api endpoint in a loop</span>

<span class="sd">        :param delay: number of seconds to wait between api calls.</span>
<span class="sd">         Note Connection &#39;requests_delay&#39; also apply.</span>
<span class="sd">        :return: tuple of status and percentage complete</span>
<span class="sd">        :rtype: tuple(str, float)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">item_id</span><span class="p">:</span>
            <span class="k">while</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_request_status</span><span class="p">():</span>
                <span class="c1"># wait until _request_status returns True</span>
                <span class="k">yield</span> <span class="bp">self</span><span class="o">.</span><span class="n">status</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">completion_percentage</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">item_id</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="n">sleep</span><span class="p">(</span><span class="n">delay</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">yield</span> <span class="bp">self</span><span class="o">.</span><span class="n">status</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">completion_percentage</span></div>

<div class="viewcode-block" id="CopyOperation.get_item"><a class="viewcode-back" href="../../api/drive.html#O365.drive.CopyOperation.get_item">[docs]</a>    <span class="k">def</span> <span class="nf">get_item</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns the item copied</span>

<span class="sd">        :return: Copied Item</span>
<span class="sd">        :rtype: DriveItem</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">get_item</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">item_id</span><span class="p">)</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">item_id</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span></div></div>


<div class="viewcode-block" id="DriveItemVersion"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItemVersion">[docs]</a><span class="k">class</span> <span class="nc">DriveItemVersion</span><span class="p">(</span><span class="n">ApiComponent</span><span class="p">,</span> <span class="n">DownloadableMixin</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; A version of a DriveItem &quot;&quot;&quot;</span>

    <span class="n">_endpoints</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;download&#39;</span><span class="p">:</span> <span class="s1">&#39;/versions/</span><span class="si">{id}</span><span class="s1">/content&#39;</span><span class="p">,</span>
        <span class="s1">&#39;restore&#39;</span><span class="p">:</span> <span class="s1">&#39;/versions/</span><span class="si">{id}</span><span class="s1">/restoreVersion&#39;</span>
    <span class="p">}</span>

<div class="viewcode-block" id="DriveItemVersion.__init__"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItemVersion.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">con</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Version of DriveItem</span>

<span class="sd">        :param parent: parent for this operation</span>
<span class="sd">        :type parent: DriveItem</span>
<span class="sd">        :param Connection con: connection to use if no parent specified</span>
<span class="sd">        :param Protocol protocol: protocol to use if no parent specified</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        :param str main_resource: use this resource instead of parent resource</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">parent</span> <span class="ow">and</span> <span class="n">con</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Need a parent or a connection but not both&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">con</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">con</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">con</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_parent</span> <span class="o">=</span> <span class="n">parent</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">DriveItem</span><span class="p">)</span> <span class="k">else</span> <span class="kc">None</span>

        <span class="n">protocol</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">protocol</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;protocol&#39;</span><span class="p">)</span>
        <span class="c1"># Choose the main_resource passed in kwargs over parent main_resource</span>
        <span class="n">main_resource</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span>
            <span class="nb">getattr</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="kc">None</span><span class="p">)</span>

        <span class="n">resource_prefix</span> <span class="o">=</span> <span class="s1">&#39;/items/</span><span class="si">{item_id}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="n">item_id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_parent</span><span class="o">.</span><span class="n">object_id</span><span class="p">)</span>
        <span class="n">main_resource</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="n">main_resource</span> <span class="ow">or</span> <span class="p">(</span><span class="n">protocol</span><span class="o">.</span><span class="n">default_resource</span> <span class="k">if</span> <span class="n">protocol</span> <span class="k">else</span> <span class="s1">&#39;&#39;</span><span class="p">),</span>
            <span class="n">resource_prefix</span><span class="p">)</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">protocol</span><span class="o">=</span><span class="n">protocol</span><span class="p">,</span> <span class="n">main_resource</span><span class="o">=</span><span class="n">main_resource</span><span class="p">)</span>

        <span class="n">cloud_data</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">,</span> <span class="p">{})</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">driveitem_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parent</span><span class="o">.</span><span class="n">object_id</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;id&#39;</span><span class="p">,</span> <span class="s1">&#39;1.0&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span>
        <span class="n">modified</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;lastModifiedDateTime&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">local_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">timezone</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">modified</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="n">modified</span><span class="p">)</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span>
            <span class="n">local_tz</span><span class="p">)</span> <span class="k">if</span> <span class="n">modified</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">size</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;size&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
        <span class="n">modified_by</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;lastModifiedBy&#39;</span><span class="p">),</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;user&#39;</span><span class="p">,</span>
                                                                         <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">modified_by</span> <span class="o">=</span> <span class="n">Contact</span><span class="p">(</span><span class="n">con</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">modified_by</span><span class="p">})</span> <span class="k">if</span> <span class="n">modified_by</span> <span class="k">else</span> <span class="kc">None</span></div>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__repr__</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">(</span><span class="s1">&#39;Version Id: </span><span class="si">{}</span><span class="s1"> | Modified on: </span><span class="si">{}</span><span class="s1"> | by: </span><span class="si">{}</span><span class="s1">&#39;</span>
                <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                          <span class="bp">self</span><span class="o">.</span><span class="n">modified</span><span class="p">,</span>
                          <span class="bp">self</span><span class="o">.</span><span class="n">modified_by</span><span class="o">.</span><span class="n">display_name</span>
                          <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">modified_by</span> <span class="k">else</span> <span class="kc">None</span><span class="p">))</span>

<div class="viewcode-block" id="DriveItemVersion.restore"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItemVersion.restore">[docs]</a>    <span class="k">def</span> <span class="nf">restore</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Restores this DriveItem Version.</span>
<span class="sd">        You can not restore the current version (last one).</span>

<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;restore&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>

        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="n">response</span><span class="p">)</span></div>

<div class="viewcode-block" id="DriveItemVersion.download"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItemVersion.download">[docs]</a>    <span class="k">def</span> <span class="nf">download</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">to_path</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">chunk_size</span><span class="o">=</span><span class="s1">&#39;auto&#39;</span><span class="p">,</span>
                 <span class="n">convert_to_pdf</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Downloads this version.</span>
<span class="sd">        You can not download the current version (last one).</span>

<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">download</span><span class="p">(</span><span class="n">to_path</span><span class="o">=</span><span class="n">to_path</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
                                <span class="n">chunk_size</span><span class="o">=</span><span class="n">chunk_size</span><span class="p">,</span>
                                <span class="n">convert_to_pdf</span><span class="o">=</span><span class="n">convert_to_pdf</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="DriveItemPermission"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItemPermission">[docs]</a><span class="k">class</span> <span class="nc">DriveItemPermission</span><span class="p">(</span><span class="n">ApiComponent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; A Permission representation for a DriveItem &quot;&quot;&quot;</span>
    <span class="n">_endpoints</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;permission&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{driveitem_id}</span><span class="s1">/permissions/</span><span class="si">{id}</span><span class="s1">&#39;</span>
    <span class="p">}</span>

<div class="viewcode-block" id="DriveItemPermission.__init__"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItemPermission.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">con</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Permissions for DriveItem</span>

<span class="sd">        :param parent: parent for this operation</span>
<span class="sd">        :type parent: DriveItem</span>
<span class="sd">        :param Connection con: connection to use if no parent specified</span>
<span class="sd">        :param Protocol protocol: protocol to use if no parent specified</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        :param str main_resource: use this resource instead of parent resource</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">parent</span> <span class="ow">and</span> <span class="n">con</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Need a parent or a connection but not both&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">con</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">con</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">con</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_parent</span> <span class="o">=</span> <span class="n">parent</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">DriveItem</span><span class="p">)</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="c1"># Choose the main_resource passed in kwargs over parent main_resource</span>
        <span class="n">main_resource</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span>
            <span class="nb">getattr</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="kc">None</span><span class="p">)</span>

        <span class="n">protocol</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">protocol</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;protocol&#39;</span><span class="p">)</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">protocol</span><span class="o">=</span><span class="n">protocol</span><span class="p">,</span> <span class="n">main_resource</span><span class="o">=</span><span class="n">main_resource</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">driveitem_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parent</span><span class="o">.</span><span class="n">object_id</span>
        <span class="n">cloud_data</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">,</span> <span class="p">{})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;id&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">inherited_from</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;inheritedFrom&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>

        <span class="n">link</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;link&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">permission_type</span> <span class="o">=</span> <span class="s1">&#39;owner&#39;</span>
        <span class="k">if</span> <span class="n">link</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">permission_type</span> <span class="o">=</span> <span class="s1">&#39;link&#39;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">share_type</span> <span class="o">=</span> <span class="n">link</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;type&#39;</span><span class="p">,</span> <span class="s1">&#39;view&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">share_scope</span> <span class="o">=</span> <span class="n">link</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;scope&#39;</span><span class="p">,</span> <span class="s1">&#39;anonymous&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">share_link</span> <span class="o">=</span> <span class="n">link</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;webUrl&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

        <span class="n">invitation</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;invitation&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">invitation</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">permission_type</span> <span class="o">=</span> <span class="s1">&#39;invitation&#39;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">share_email</span> <span class="o">=</span> <span class="n">invitation</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;email&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
            <span class="n">invited_by</span> <span class="o">=</span> <span class="n">invitation</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;invitedBy&#39;</span><span class="p">,</span> <span class="p">{})</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">invited_by</span> <span class="o">=</span> <span class="n">invited_by</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;user&#39;</span><span class="p">,</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;displayName&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">or</span> <span class="n">invited_by</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;application&#39;</span><span class="p">,</span>
                                                                 <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;displayName&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">require_sign_in</span> <span class="o">=</span> <span class="n">invitation</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;signInRequired&#39;</span><span class="p">),</span>
                                                  <span class="kc">True</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">roles</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;roles&#39;</span><span class="p">),</span> <span class="p">[])</span>
        <span class="n">granted_to</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;grantedTo&#39;</span><span class="p">),</span> <span class="p">{})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">granted_to</span> <span class="o">=</span> <span class="n">granted_to</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;user&#39;</span><span class="p">,</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;displayName&#39;</span><span class="p">))</span> <span class="ow">or</span> <span class="n">granted_to</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;application&#39;</span><span class="p">,</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;displayName&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">share_id</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;shareId&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__repr__</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;Permission for </span><span class="si">{}</span><span class="s1"> of type: </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_parent</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                                      <span class="bp">self</span><span class="o">.</span><span class="n">permission_type</span><span class="p">)</span>

<div class="viewcode-block" id="DriveItemPermission.update_roles"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItemPermission.update_roles">[docs]</a>    <span class="k">def</span> <span class="nf">update_roles</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">roles</span><span class="o">=</span><span class="s1">&#39;view&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Updates the roles of this permission</span>

<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;permission&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="n">driveitem_id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">driveitem_id</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">roles</span> <span class="ow">in</span> <span class="p">{</span><span class="s1">&#39;view&#39;</span><span class="p">,</span> <span class="s1">&#39;read&#39;</span><span class="p">}:</span>
            <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;roles&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;read&#39;</span><span class="p">]}</span>
        <span class="k">elif</span> <span class="n">roles</span> <span class="ow">in</span> <span class="p">{</span><span class="s1">&#39;edit&#39;</span><span class="p">,</span> <span class="s1">&#39;write&#39;</span><span class="p">}:</span>
            <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;roles&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;write&#39;</span><span class="p">]}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;&quot;</span><span class="si">{}</span><span class="s1">&quot; is not a valid share_type&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">roles</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">patch</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">roles</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;roles&#39;</span><span class="p">,</span> <span class="p">[])</span>
        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="DriveItemPermission.delete"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItemPermission.delete">[docs]</a>    <span class="k">def</span> <span class="nf">delete</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Deletes this permission. Only permissions that are not</span>
<span class="sd">        inherited can be deleted.</span>

<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;permission&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="n">driveitem_id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">driveitem_id</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">return</span> <span class="kc">True</span></div></div>


<div class="viewcode-block" id="DriveItem"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem">[docs]</a><span class="k">class</span> <span class="nc">DriveItem</span><span class="p">(</span><span class="n">ApiComponent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; A DriveItem representation. Groups all functionality &quot;&quot;&quot;</span>

    <span class="n">_endpoints</span> <span class="o">=</span> <span class="p">{</span>
        <span class="c1"># all prefixed with /drives/{drive_id} on main_resource by default</span>
        <span class="s1">&#39;list_items&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{id}</span><span class="s1">/children&#39;</span><span class="p">,</span>
        <span class="s1">&#39;thumbnails&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{id}</span><span class="s1">/thumbnails&#39;</span><span class="p">,</span>
        <span class="s1">&#39;item&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{id}</span><span class="s1">&#39;</span><span class="p">,</span>
        <span class="s1">&#39;copy&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{id}</span><span class="s1">/copy&#39;</span><span class="p">,</span>
        <span class="s1">&#39;download&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{id}</span><span class="s1">/content&#39;</span><span class="p">,</span>
        <span class="s1">&#39;search&#39;</span><span class="p">:</span> <span class="s2">&quot;/items/</span><span class="si">{id}</span><span class="s2">/search(q=&#39;</span><span class="si">{search_text}</span><span class="s2">&#39;)&quot;</span><span class="p">,</span>
        <span class="s1">&#39;versions&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{id}</span><span class="s1">/versions&#39;</span><span class="p">,</span>
        <span class="s1">&#39;version&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{id}</span><span class="s1">/versions/</span><span class="si">{version_id}</span><span class="s1">&#39;</span><span class="p">,</span>
        <span class="s1">&#39;simple_upload&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{id}</span><span class="s1">:/</span><span class="si">{filename}</span><span class="s1">:/content&#39;</span><span class="p">,</span>
        <span class="s1">&#39;create_upload_session&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{id}</span><span class="s1">:/</span><span class="si">{filename}</span><span class="s1">:/createUploadSession&#39;</span><span class="p">,</span>
        <span class="s1">&#39;share_link&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{id}</span><span class="s1">/createLink&#39;</span><span class="p">,</span>
        <span class="s1">&#39;share_invite&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{id}</span><span class="s1">/invite&#39;</span><span class="p">,</span>
        <span class="s1">&#39;permissions&#39;</span><span class="p">:</span> <span class="s1">&#39;/items/</span><span class="si">{id}</span><span class="s1">/permissions&#39;</span><span class="p">,</span>
    <span class="p">}</span>

<div class="viewcode-block" id="DriveItem.__init__"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">con</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Create a DriveItem</span>

<span class="sd">        :param parent: parent for this operation</span>
<span class="sd">        :type parent: Drive or drive.Folder</span>
<span class="sd">        :param Connection con: connection to use if no parent specified</span>
<span class="sd">        :param Protocol protocol: protocol to use if no parent specified</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        :param str main_resource: use this resource instead of parent resource</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">parent</span> <span class="ow">and</span> <span class="n">con</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Need a parent or a connection but not both&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">con</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">con</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">con</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_parent</span> <span class="o">=</span> <span class="n">parent</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">DriveItem</span><span class="p">)</span> <span class="k">else</span> <span class="kc">None</span>

        <span class="c1"># Choose the main_resource passed in kwargs over parent main_resource</span>
        <span class="n">main_resource</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span>
            <span class="nb">getattr</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="kc">None</span><span class="p">)</span>

        <span class="n">protocol</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">protocol</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;protocol&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">parent</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">DriveItem</span><span class="p">):</span>
            <span class="c1"># parent is a Drive so append the drive route to the main_resource</span>
            <span class="n">drive_id</span> <span class="o">=</span> <span class="p">(</span><span class="kc">None</span> <span class="k">if</span> <span class="n">parent</span><span class="o">.</span><span class="n">object_id</span> <span class="o">==</span> <span class="s1">&#39;root&#39;</span>
                        <span class="k">else</span> <span class="n">parent</span><span class="o">.</span><span class="n">object_id</span><span class="p">)</span> <span class="ow">or</span> <span class="kc">None</span>

            <span class="c1"># prefix with the current known drive or the default one</span>
            <span class="n">resource_prefix</span> <span class="o">=</span> <span class="s1">&#39;/drives/</span><span class="si">{drive_id}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">drive_id</span><span class="o">=</span><span class="n">drive_id</span><span class="p">)</span> <span class="k">if</span> <span class="n">drive_id</span> <span class="k">else</span> <span class="s1">&#39;/drive&#39;</span>
            <span class="n">main_resource</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">main_resource</span> <span class="ow">or</span> <span class="p">(</span>
                <span class="n">protocol</span><span class="o">.</span><span class="n">default_resource</span> <span class="k">if</span> <span class="n">protocol</span> <span class="k">else</span> <span class="s1">&#39;&#39;</span><span class="p">),</span> <span class="n">resource_prefix</span><span class="p">)</span>

        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">protocol</span><span class="o">=</span><span class="n">protocol</span><span class="p">,</span> <span class="n">main_resource</span><span class="o">=</span><span class="n">main_resource</span><span class="p">)</span>

        <span class="n">cloud_data</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">,</span> <span class="p">{})</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;id&#39;</span><span class="p">))</span>

        <span class="n">parent_reference</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;parentReference&#39;</span><span class="p">),</span> <span class="p">{})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent_id</span> <span class="o">=</span> <span class="n">parent_reference</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;id&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">drive_id</span> <span class="o">=</span> <span class="n">parent_reference</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;driveId&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent_path</span> <span class="o">=</span> <span class="n">parent_reference</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s2">&quot;path&quot;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>

        <span class="n">remote_item</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;remoteItem&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">remote_item</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">drive</span> <span class="o">=</span> <span class="kc">None</span>  <span class="c1"># drive is unknown?</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">remote_item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">(</span><span class="n">remote_item</span><span class="p">)(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">remote_item</span><span class="p">})</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">parent_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_item</span><span class="o">.</span><span class="n">parent_id</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">drive_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_item</span><span class="o">.</span><span class="n">drive_id</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">set_base_url</span><span class="p">(</span><span class="s1">&#39;drives/</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">drive_id</span><span class="p">))</span>  <span class="c1"># changes main_resource and _base_url</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">drive</span> <span class="o">=</span> <span class="n">parent</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">Drive</span><span class="p">)</span> <span class="k">else</span> <span class="p">(</span>
                <span class="n">parent</span><span class="o">.</span><span class="n">drive</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">drive</span><span class="p">,</span> <span class="n">Drive</span><span class="p">)</span> <span class="k">else</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
                    <span class="s1">&#39;drive&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">remote_item</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">),</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">web_url</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;webUrl&#39;</span><span class="p">))</span>
        <span class="n">created_by</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;createdBy&#39;</span><span class="p">),</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;user&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">created_by</span> <span class="o">=</span> <span class="n">Contact</span><span class="p">(</span><span class="n">con</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">created_by</span><span class="p">})</span> <span class="k">if</span> <span class="n">created_by</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="n">modified_by</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;lastModifiedBy&#39;</span><span class="p">),</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;user&#39;</span><span class="p">,</span>
                                                                         <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">modified_by</span> <span class="o">=</span> <span class="n">Contact</span><span class="p">(</span><span class="n">con</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">modified_by</span><span class="p">})</span> <span class="k">if</span> <span class="n">modified_by</span> <span class="k">else</span> <span class="kc">None</span>

        <span class="n">created</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;createdDateTime&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">modified</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;lastModifiedDateTime&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">local_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">timezone</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">created</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="n">created</span><span class="p">)</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span><span class="n">local_tz</span><span class="p">)</span> <span class="k">if</span> <span class="n">created</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">modified</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="n">modified</span><span class="p">)</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span>
            <span class="n">local_tz</span><span class="p">)</span> <span class="k">if</span> <span class="n">modified</span> <span class="k">else</span> <span class="kc">None</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">description</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;description&#39;</span><span class="p">),</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">size</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;size&#39;</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">shared</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;shared&#39;</span><span class="p">),</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;scope&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

        <span class="c1"># Thumbnails</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">thumbnails</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;thumbnails&#39;</span><span class="p">),</span> <span class="p">[])</span></div>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__repr__</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">: </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="n">obj_id</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="s1">&#39;object_id&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">obj_id</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="o">==</span> <span class="n">obj_id</span>
        <span class="k">return</span> <span class="kc">False</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">_classifier</span><span class="p">(</span><span class="n">item</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Subclass to change factory classes &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="s1">&#39;folder&#39;</span> <span class="ow">in</span> <span class="n">item</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Folder</span>
        <span class="k">elif</span> <span class="s1">&#39;image&#39;</span> <span class="ow">in</span> <span class="n">item</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Image</span>
        <span class="k">elif</span> <span class="s1">&#39;photo&#39;</span> <span class="ow">in</span> <span class="n">item</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Photo</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">File</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_folder</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns if this DriveItem is a Folder &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">Folder</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_file</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns if this DriveItem is a File &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">File</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_image</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns if this DriveItem is a Image &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">Image</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">is_photo</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns if this DriveItem is a Photo &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">Photo</span><span class="p">)</span>

<div class="viewcode-block" id="DriveItem.get_parent"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem.get_parent">[docs]</a>    <span class="k">def</span> <span class="nf">get_parent</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; the parent of this DriveItem</span>

<span class="sd">        :return: Parent of this item</span>
<span class="sd">        :rtype: Drive or drive.Folder</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parent</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parent</span><span class="o">.</span><span class="n">object_id</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parent</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent_id</span><span class="p">:</span>
                <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">drive</span><span class="o">.</span><span class="n">get_item</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent_id</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c1"># return the drive</span>
                <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">drive</span></div>

<div class="viewcode-block" id="DriveItem.get_drive"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem.get_drive">[docs]</a>    <span class="k">def</span> <span class="nf">get_drive</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns this item drive</span>
<span class="sd">        :return: Drive of this item</span>
<span class="sd">        :rtype: Drive or None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">drive_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">drive</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="k">return</span> <span class="n">Drive</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">main_resource</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">drive</span><span class="p">})</span></div>

<div class="viewcode-block" id="DriveItem.get_thumbnails"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem.get_thumbnails">[docs]</a>    <span class="k">def</span> <span class="nf">get_thumbnails</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns this Item Thumbnails. Thumbnails are not supported on</span>
<span class="sd">        SharePoint Server 2016.</span>

<span class="sd">        :param size: request only the specified size: ej: &quot;small&quot;,</span>
<span class="sd">         Custom 300x400 px: &quot;c300x400&quot;, Crop: &quot;c300x400_Crop&quot;</span>
<span class="sd">        :return: Thumbnail Data</span>
<span class="sd">        :rtype: dict</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[]</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;thumbnails&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">params</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="n">size</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">params</span><span class="p">[</span><span class="s1">&#39;select&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">size</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[]</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">thumbnails</span> <span class="ow">or</span> <span class="n">size</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">thumbnails</span> <span class="o">=</span> <span class="n">data</span>

        <span class="k">return</span> <span class="n">data</span></div>

<div class="viewcode-block" id="DriveItem.update"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem.update">[docs]</a>    <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Updates this item</span>

<span class="sd">        :param kwargs: all the properties to be updated.</span>
<span class="sd">         only name and description are allowed at the moment.</span>
<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="n">key</span><span class="p">):</span> <span class="n">value</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span>
                <span class="n">key</span> <span class="ow">in</span> <span class="p">{</span><span class="s1">&#39;name&#39;</span><span class="p">,</span>
                        <span class="s1">&#39;description&#39;</span><span class="p">}}</span>  <span class="c1"># convert keys to protocol casing</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">data</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">patch</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="n">new_data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
            <span class="n">value</span> <span class="o">=</span> <span class="n">new_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">value</span><span class="p">:</span>
                <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">to_api_case</span><span class="p">(</span><span class="n">key</span><span class="p">),</span> <span class="n">value</span><span class="p">)</span>

        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="DriveItem.delete"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem.delete">[docs]</a>    <span class="k">def</span> <span class="nf">delete</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Moves this item to the Recycle Bin</span>

<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="DriveItem.move"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem.move">[docs]</a>    <span class="k">def</span> <span class="nf">move</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">target</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Moves this DriveItem to another Folder.</span>
<span class="sd">        Can&#39;t move between different Drives.</span>

<span class="sd">        :param target: a Folder, Drive item or Item Id string.</span>
<span class="sd">         If it&#39;s a drive the item will be moved to the root folder.</span>
<span class="sd">        :type target: drive.Folder or DriveItem or str</span>
<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">Folder</span><span class="p">):</span>
            <span class="n">target_id</span> <span class="o">=</span> <span class="n">target</span><span class="o">.</span><span class="n">object_id</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">Drive</span><span class="p">):</span>
            <span class="c1"># we need the root folder id</span>
            <span class="n">root_folder</span> <span class="o">=</span> <span class="n">target</span><span class="o">.</span><span class="n">get_root_folder</span><span class="p">()</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">root_folder</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">False</span>
            <span class="n">target_id</span> <span class="o">=</span> <span class="n">root_folder</span><span class="o">.</span><span class="n">object_id</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">target_id</span> <span class="o">=</span> <span class="n">target</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Target must be a Folder or Drive&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">target_id</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s1">&#39;Both self, and target must have a valid object_id.&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">target_id</span> <span class="o">==</span> <span class="s1">&#39;root&#39;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;When moving, target id can&#39;t be &#39;root&#39;&quot;</span><span class="p">)</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;item&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;parentReference&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span> <span class="n">target_id</span><span class="p">}}</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">patch</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">parent_id</span> <span class="o">=</span> <span class="n">target_id</span>

        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="DriveItem.copy"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem.copy">[docs]</a>    <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Asynchronously creates a copy of this DriveItem and all it&#39;s</span>
<span class="sd">        child elements.</span>

<span class="sd">        :param target: target location to move to.</span>
<span class="sd">         If it&#39;s a drive the item will be moved to the root folder.</span>
<span class="sd">        :type target: drive.Folder or Drive</span>
<span class="sd">        :param name: a new name for the copy.</span>
<span class="sd">        :rtype: CopyOperation</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">target</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">name</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Must provide a target or a name (or both)&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">Folder</span><span class="p">):</span>
            <span class="n">target_id</span> <span class="o">=</span> <span class="n">target</span><span class="o">.</span><span class="n">object_id</span>
            <span class="n">drive_id</span> <span class="o">=</span> <span class="n">target</span><span class="o">.</span><span class="n">drive_id</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">Drive</span><span class="p">):</span>
            <span class="c1"># we need the root folder</span>
            <span class="n">root_folder</span> <span class="o">=</span> <span class="n">target</span><span class="o">.</span><span class="n">get_root_folder</span><span class="p">()</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">root_folder</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">None</span>
            <span class="n">target_id</span> <span class="o">=</span> <span class="n">root_folder</span><span class="o">.</span><span class="n">object_id</span>
            <span class="n">drive_id</span> <span class="o">=</span> <span class="n">root_folder</span><span class="o">.</span><span class="n">drive_id</span>
        <span class="k">elif</span> <span class="n">target</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">target_id</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="n">drive_id</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Target, if provided, must be a Folder or Drive&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="n">target_id</span> <span class="o">==</span> <span class="s1">&#39;root&#39;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;When copying, target id can&#39;t be &#39;root&#39;&quot;</span><span class="p">)</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;copy&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">target_id</span> <span class="ow">and</span> <span class="n">drive_id</span><span class="p">:</span>
            <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;parentReference&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span> <span class="n">target_id</span><span class="p">,</span> <span class="s1">&#39;driveId&#39;</span><span class="p">:</span> <span class="n">drive_id</span><span class="p">}}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">data</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="n">name</span><span class="p">:</span>
            <span class="c1"># incorporate the extension if the name provided has none.</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">Path</span><span class="p">(</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">suffix</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
                <span class="n">name</span> <span class="o">=</span> <span class="n">name</span> <span class="o">+</span> <span class="n">Path</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">suffix</span>
            <span class="n">data</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">name</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="c1"># Find out if the server has run a Sync or Async operation</span>
        <span class="n">location</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Location&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

        <span class="k">if</span> <span class="s1">&#39;monitor&#39;</span> <span class="ow">in</span> <span class="n">location</span><span class="p">:</span>
            <span class="c1"># Async operation</span>
            <span class="k">return</span> <span class="n">CopyOperation</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">drive</span><span class="p">,</span> <span class="n">monitor_url</span><span class="o">=</span><span class="n">location</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Sync operation. Item is ready to be retrieved</span>
            <span class="n">path</span> <span class="o">=</span> <span class="n">urlparse</span><span class="p">(</span><span class="n">location</span><span class="p">)</span><span class="o">.</span><span class="n">path</span>
            <span class="n">item_id</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">return</span> <span class="n">CopyOperation</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">drive</span><span class="p">,</span> <span class="n">item_id</span><span class="o">=</span><span class="n">item_id</span><span class="p">)</span></div>

<div class="viewcode-block" id="DriveItem.get_versions"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem.get_versions">[docs]</a>    <span class="k">def</span> <span class="nf">get_versions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns a list of available versions for this item</span>

<span class="sd">        :return: list of versions</span>
<span class="sd">        :rtype: list[DriveItemVersion]</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[]</span>
        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;versions&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[]</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">DriveItemVersion</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">item</span><span class="p">})</span>
                <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;value&#39;</span><span class="p">,</span> <span class="p">[])]</span></div>

<div class="viewcode-block" id="DriveItem.get_version"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem.get_version">[docs]</a>    <span class="k">def</span> <span class="nf">get_version</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">version_id</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns a version for specified id</span>

<span class="sd">        :return: a version object of specified id</span>
<span class="sd">        :rtype: DriveItemVersion</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;version&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">,</span>
                                                  <span class="n">version_id</span><span class="o">=</span><span class="n">version_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="k">return</span> <span class="n">DriveItemVersion</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">data</span><span class="p">})</span></div>

<div class="viewcode-block" id="DriveItem.share_with_link"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem.share_with_link">[docs]</a>    <span class="k">def</span> <span class="nf">share_with_link</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">share_type</span><span class="o">=</span><span class="s1">&#39;view&#39;</span><span class="p">,</span> <span class="n">share_scope</span><span class="o">=</span><span class="s1">&#39;anonymous&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Creates or returns a link you can share with others</span>

<span class="sd">        :param str share_type: &#39;view&#39; to allow only view access,</span>
<span class="sd">         &#39;edit&#39; to allow editions, and</span>
<span class="sd">         &#39;embed&#39; to allow the DriveItem to be embedded</span>
<span class="sd">        :param str share_scope: &#39;anonymous&#39;: anyone with the link can access.</span>
<span class="sd">         &#39;organization&#39; Only organization members can access</span>
<span class="sd">        :return: link to share</span>
<span class="sd">        :rtype: DriveItemPermission</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;share_link&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="n">share_type</span><span class="p">,</span>
            <span class="s1">&#39;scope&#39;</span><span class="p">:</span> <span class="n">share_scope</span>
        <span class="p">}</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># return data.get(&#39;link&#39;, {}).get(&#39;webUrl&#39;)</span>
        <span class="k">return</span> <span class="n">DriveItemPermission</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">data</span><span class="p">})</span></div>

<div class="viewcode-block" id="DriveItem.share_with_invite"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem.share_with_invite">[docs]</a>    <span class="k">def</span> <span class="nf">share_with_invite</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">recipients</span><span class="p">,</span> <span class="n">require_sign_in</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                          <span class="n">send_email</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">message</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">share_type</span><span class="o">=</span><span class="s1">&#39;view&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Sends an invitation to access or edit this DriveItem</span>

<span class="sd">        :param recipients: a string or Contact or a list of the former</span>
<span class="sd">         representing recipients of this invitation</span>
<span class="sd">        :type recipients: list[str] or list[Contact] or str or Contact</span>
<span class="sd">        :param bool require_sign_in: if True the recipients</span>
<span class="sd">         invited will need to log in to view the contents</span>
<span class="sd">        :param bool send_email: if True an email will be send to the recipients</span>
<span class="sd">        :param str message: the body text of the message emailed</span>
<span class="sd">        :param str share_type: &#39;view&#39;: will allow to read the contents.</span>
<span class="sd">         &#39;edit&#39; will allow to modify the contents</span>
<span class="sd">        :return: link to share</span>
<span class="sd">        :rtype: DriveItemPermission</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">to</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="n">recipients</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Provide a valid to parameter&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">recipients</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
            <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">recipients</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
                    <span class="n">to</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;email&#39;</span><span class="p">:</span> <span class="n">x</span><span class="p">})</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">Contact</span><span class="p">):</span>
                    <span class="n">to</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;email&#39;</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">main_email</span><span class="p">})</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                        <span class="s1">&#39;All the recipients must be either strings or Contacts&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">recipients</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">to</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;email&#39;</span><span class="p">:</span> <span class="n">recipients</span><span class="p">})</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">recipients</span><span class="p">,</span> <span class="n">Contact</span><span class="p">):</span>
            <span class="n">to</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;email&#39;</span><span class="p">:</span> <span class="n">recipients</span><span class="o">.</span><span class="n">main_email</span><span class="p">})</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s1">&#39;All the recipients must be either strings or Contacts&#39;</span><span class="p">)</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;share_invite&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s1">&#39;recipients&#39;</span><span class="p">:</span> <span class="n">to</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;requireSignIn&#39;</span><span class="p">):</span> <span class="n">require_sign_in</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;sendInvitation&#39;</span><span class="p">):</span> <span class="n">send_email</span><span class="p">,</span>
        <span class="p">}</span>
        <span class="k">if</span> <span class="n">share_type</span> <span class="ow">in</span> <span class="p">{</span><span class="s1">&#39;view&#39;</span><span class="p">,</span> <span class="s1">&#39;read&#39;</span><span class="p">}:</span>
            <span class="n">data</span><span class="p">[</span><span class="s1">&#39;roles&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;read&#39;</span><span class="p">]</span>
        <span class="k">elif</span> <span class="n">share_type</span> <span class="ow">in</span> <span class="p">{</span><span class="s1">&#39;edit&#39;</span><span class="p">,</span> <span class="s1">&#39;write&#39;</span><span class="p">}:</span>
            <span class="n">data</span><span class="p">[</span><span class="s1">&#39;roles&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;write&#39;</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s1">&#39;&quot;</span><span class="si">{}</span><span class="s1">&quot; is not a valid share_type&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">share_type</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">send_email</span> <span class="ow">and</span> <span class="n">message</span><span class="p">:</span>
            <span class="n">data</span><span class="p">[</span><span class="s1">&#39;message&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">message</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="k">return</span> <span class="n">DriveItemPermission</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">data</span><span class="p">})</span></div>

<div class="viewcode-block" id="DriveItem.get_permissions"><a class="viewcode-back" href="../../api/drive.html#O365.drive.DriveItem.get_permissions">[docs]</a>    <span class="k">def</span> <span class="nf">get_permissions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns a list of DriveItemPermissions with the</span>
<span class="sd">        permissions granted for this DriveItem.</span>

<span class="sd">        :return: List of Permissions</span>
<span class="sd">        :rtype: list[DriveItemPermission]</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[]</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;permissions&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">DriveItemPermission</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">item</span><span class="p">})</span>
                <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;value&#39;</span><span class="p">,</span> <span class="p">[])]</span></div></div>


<div class="viewcode-block" id="File"><a class="viewcode-back" href="../../api/drive.html#O365.drive.File">[docs]</a><span class="k">class</span> <span class="nc">File</span><span class="p">(</span><span class="n">DriveItem</span><span class="p">,</span> <span class="n">DownloadableMixin</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; A File &quot;&quot;&quot;</span>

<div class="viewcode-block" id="File.__init__"><a class="viewcode-back" href="../../api/drive.html#O365.drive.File.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">cloud_data</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">,</span> <span class="p">{})</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">mime_type</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;file&#39;</span><span class="p">),</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;mimeType&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">extension</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">Path</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span><span class="o">.</span><span class="n">suffix</span></div>


<div class="viewcode-block" id="Image"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Image">[docs]</a><span class="k">class</span> <span class="nc">Image</span><span class="p">(</span><span class="n">File</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; An Image &quot;&quot;&quot;</span>

<div class="viewcode-block" id="Image.__init__"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Image.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">cloud_data</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">,</span> <span class="p">{})</span>

        <span class="n">image</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;image&#39;</span><span class="p">),</span> <span class="p">{})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">height</span> <span class="o">=</span> <span class="n">image</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;height&#39;</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">width</span> <span class="o">=</span> <span class="n">image</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;width&#39;</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">dimensions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Dimension of the Image</span>

<span class="sd">        :return: width x height</span>
<span class="sd">        :rtype: str</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">x</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">width</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">height</span><span class="p">)</span></div>


<div class="viewcode-block" id="Photo"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Photo">[docs]</a><span class="k">class</span> <span class="nc">Photo</span><span class="p">(</span><span class="n">Image</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Photo Object. Inherits from Image but has more attributes &quot;&quot;&quot;</span>

<div class="viewcode-block" id="Photo.__init__"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Photo.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">cloud_data</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">,</span> <span class="p">{})</span>

        <span class="n">photo</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;photo&#39;</span><span class="p">),</span> <span class="p">{})</span>

        <span class="n">taken</span> <span class="o">=</span> <span class="n">photo</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;takenDateTime&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">local_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">timezone</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">taken_datetime</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="n">taken</span><span class="p">)</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span>
            <span class="n">local_tz</span><span class="p">)</span> <span class="k">if</span> <span class="n">taken</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">camera_make</span> <span class="o">=</span> <span class="n">photo</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;cameraMake&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">camera_model</span> <span class="o">=</span> <span class="n">photo</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;cameraModel&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">exposure_denominator</span> <span class="o">=</span> <span class="n">photo</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;exposureDenominator&#39;</span><span class="p">),</span>
                                              <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">exposure_numerator</span> <span class="o">=</span> <span class="n">photo</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;exposureNumerator&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fnumber</span> <span class="o">=</span> <span class="n">photo</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;fNumber&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">focal_length</span> <span class="o">=</span> <span class="n">photo</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;focalLength&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">iso</span> <span class="o">=</span> <span class="n">photo</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;iso&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="Folder"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Folder">[docs]</a><span class="k">class</span> <span class="nc">Folder</span><span class="p">(</span><span class="n">DriveItem</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; A Folder inside a Drive &quot;&quot;&quot;</span>

<div class="viewcode-block" id="Folder.__init__"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Folder.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">cloud_data</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">,</span> <span class="p">{})</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">child_count</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;folder&#39;</span><span class="p">),</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;childCount&#39;</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">special_folder</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;specialFolder&#39;</span><span class="p">),</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
            <span class="s1">&#39;name&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span></div>

<div class="viewcode-block" id="Folder.get_items"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Folder.get_items">[docs]</a>    <span class="k">def</span> <span class="nf">get_items</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">order_by</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">batch</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns generator all the items inside this folder</span>

<span class="sd">        :param int limit: max no. of folders to get. Over 999 uses batch.</span>
<span class="sd">        :param query: applies a OData filter to the request</span>
<span class="sd">        :type query: Query or str</span>
<span class="sd">        :param order_by: orders the result set based on this condition</span>
<span class="sd">        :type order_by: Query or str</span>
<span class="sd">        :param int batch: batch size, retrieves items in</span>
<span class="sd">         batches allowing to retrieve more items than the limit.</span>
<span class="sd">        :return: items in this folder</span>
<span class="sd">        :rtype: generator of DriveItem or Pagination</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;list_items&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">limit</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">limit</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">max_top_value</span><span class="p">:</span>
            <span class="n">batch</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">max_top_value</span>

        <span class="n">params</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;$top&#39;</span><span class="p">:</span> <span class="n">batch</span> <span class="k">if</span> <span class="n">batch</span> <span class="k">else</span> <span class="n">limit</span><span class="p">}</span>

        <span class="k">if</span> <span class="n">order_by</span><span class="p">:</span>
            <span class="n">params</span><span class="p">[</span><span class="s1">&#39;$orderby&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">order_by</span>

        <span class="k">if</span> <span class="n">query</span><span class="p">:</span>
            <span class="c1"># if query.has_filters:</span>
            <span class="c1">#     warnings.warn(&#39;Filters are not allowed by the &#39;</span>
            <span class="c1">#                   &#39;Api Provider in this method&#39;)</span>
            <span class="c1">#     query.clear_filters()</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">query</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
                <span class="n">params</span><span class="p">[</span><span class="s1">&#39;$filter&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">query</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">params</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">query</span><span class="o">.</span><span class="n">as_params</span><span class="p">())</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">iter</span><span class="p">(())</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="n">items</span> <span class="o">=</span> <span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">(</span><span class="n">item</span><span class="p">)(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">item</span><span class="p">})</span>
            <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;value&#39;</span><span class="p">,</span> <span class="p">[]))</span>
        <span class="n">next_link</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">NEXT_LINK_KEYWORD</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">batch</span> <span class="ow">and</span> <span class="n">next_link</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Pagination</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">items</span><span class="p">,</span>
                              <span class="n">constructor</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">,</span>
                              <span class="n">next_link</span><span class="o">=</span><span class="n">next_link</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">items</span></div>

<div class="viewcode-block" id="Folder.get_child_folders"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Folder.get_child_folders">[docs]</a>    <span class="k">def</span> <span class="nf">get_child_folders</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">order_by</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">batch</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns all the folders inside this folder</span>

<span class="sd">        :param int limit: max no. of folders to get. Over 999 uses batch.</span>
<span class="sd">        :param query: applies a OData filter to the request</span>
<span class="sd">        :type query: Query or str</span>
<span class="sd">        :param order_by: orders the result set based on this condition</span>
<span class="sd">        :type order_by: Query or str</span>
<span class="sd">        :param int batch: batch size, retrieves items in</span>
<span class="sd">         batches allowing to retrieve more items than the limit.</span>
<span class="sd">        :return: folder items in this folder</span>
<span class="sd">        :rtype: generator of DriveItem or Pagination</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">query</span><span class="p">:</span>
            <span class="n">query</span> <span class="o">=</span> <span class="n">query</span><span class="o">.</span><span class="n">on_attribute</span><span class="p">(</span><span class="s1">&#39;folder&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">unequal</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">query</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="p">(</span><span class="s1">&#39;folder&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">unequal</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_items</span><span class="p">(</span><span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="n">query</span><span class="p">,</span> <span class="n">order_by</span><span class="o">=</span><span class="n">order_by</span><span class="p">,</span> <span class="n">batch</span><span class="o">=</span><span class="n">batch</span><span class="p">)</span></div>

<div class="viewcode-block" id="Folder.create_child_folder"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Folder.create_child_folder">[docs]</a>    <span class="k">def</span> <span class="nf">create_child_folder</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Creates a Child Folder</span>

<span class="sd">        :param str name: the name of the new child folder</span>
<span class="sd">        :param str description: the description of the new child folder</span>
<span class="sd">        :return: newly created folder</span>
<span class="sd">        :rtype: drive.Folder</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;list_items&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="n">name</span><span class="p">,</span> <span class="s1">&#39;folder&#39;</span><span class="p">:</span> <span class="p">{}}</span>
        <span class="k">if</span> <span class="n">description</span><span class="p">:</span>
            <span class="n">data</span><span class="p">[</span><span class="s1">&#39;description&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">description</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">folder</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">(</span><span class="n">folder</span><span class="p">)(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span>
                                        <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">folder</span><span class="p">})</span></div>

<div class="viewcode-block" id="Folder.download_contents"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Folder.download_contents">[docs]</a>    <span class="k">def</span> <span class="nf">download_contents</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">to_folder</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; This will download each file and folder sequentially.</span>
<span class="sd">        Caution when downloading big folder structures</span>

<span class="sd">        :param drive.Folder to_folder: folder where to store the contents</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">to_folder</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">to_folder</span> <span class="o">=</span> <span class="n">Path</span><span class="p">()</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>
            <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                <span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Could not create folder with name: </span><span class="si">{}</span><span class="s1">. Error: </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">e</span><span class="p">))</span>
                <span class="n">to_folder</span> <span class="o">=</span> <span class="n">Path</span><span class="p">()</span>  <span class="c1"># fallback to the same folder</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">to_folder</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span>
            <span class="n">to_folder</span><span class="o">.</span><span class="n">mkdir</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_items</span><span class="p">(</span><span class="n">query</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">new_query</span><span class="p">()</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="s1">&#39;id&#39;</span><span class="p">,</span> <span class="s1">&#39;size&#39;</span><span class="p">,</span> <span class="s1">&#39;folder&#39;</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">)):</span>
            <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">is_folder</span> <span class="ow">and</span> <span class="n">item</span><span class="o">.</span><span class="n">child_count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">item</span><span class="o">.</span><span class="n">download_contents</span><span class="p">(</span><span class="n">to_folder</span><span class="o">=</span><span class="n">to_folder</span> <span class="o">/</span> <span class="n">item</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">item</span><span class="o">.</span><span class="n">download</span><span class="p">(</span><span class="n">to_folder</span><span class="p">)</span></div>

<div class="viewcode-block" id="Folder.search"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Folder.search">[docs]</a>    <span class="k">def</span> <span class="nf">search</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_text</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">order_by</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
               <span class="n">batch</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Search for DriveItems under this folder</span>
<span class="sd">        The search API uses a search service under the covers,</span>
<span class="sd">        which requires indexing of content.</span>

<span class="sd">        As a result, there will be some time between creation of an item</span>
<span class="sd">        and when it will appear in search results.</span>

<span class="sd">        :param str search_text: The query text used to search for items.</span>
<span class="sd">         Values may be matched across several fields including filename,</span>
<span class="sd">         metadata, and file content.</span>
<span class="sd">        :param int limit: max no. of folders to get. Over 999 uses batch.</span>
<span class="sd">        :param query: applies a OData filter to the request</span>
<span class="sd">        :type query: Query or str</span>
<span class="sd">        :param order_by: orders the result set based on this condition</span>
<span class="sd">        :type order_by: Query or str</span>
<span class="sd">        :param int batch: batch size, retrieves items in</span>
<span class="sd">         batches allowing to retrieve more items than the limit.</span>
<span class="sd">        :return: items in this folder matching search</span>
<span class="sd">        :rtype: generator of DriveItem or Pagination</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">search_text</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">search_text</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Provide a valid search_text&#39;</span><span class="p">)</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;search&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">,</span>
                                                 <span class="n">search_text</span><span class="o">=</span><span class="n">search_text</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">limit</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">limit</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">max_top_value</span><span class="p">:</span>
            <span class="n">batch</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">max_top_value</span>

        <span class="n">params</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;$top&#39;</span><span class="p">:</span> <span class="n">batch</span> <span class="k">if</span> <span class="n">batch</span> <span class="k">else</span> <span class="n">limit</span><span class="p">}</span>

        <span class="k">if</span> <span class="n">order_by</span><span class="p">:</span>
            <span class="n">params</span><span class="p">[</span><span class="s1">&#39;$orderby&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">order_by</span>

        <span class="k">if</span> <span class="n">query</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">query</span><span class="o">.</span><span class="n">has_filters</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                    <span class="s1">&#39;Filters are not allowed by the Api &#39;</span>
                    <span class="s1">&#39;Provider in this method&#39;</span><span class="p">)</span>
                <span class="n">query</span><span class="o">.</span><span class="n">clear_filters</span><span class="p">()</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">query</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
                <span class="n">params</span><span class="p">[</span><span class="s1">&#39;$filter&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">query</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">params</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">query</span><span class="o">.</span><span class="n">as_params</span><span class="p">())</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">iter</span><span class="p">(())</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="n">items</span> <span class="o">=</span> <span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">(</span><span class="n">item</span><span class="p">)(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">item</span><span class="p">})</span>
            <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;value&#39;</span><span class="p">,</span> <span class="p">[]))</span>
        <span class="n">next_link</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">NEXT_LINK_KEYWORD</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">batch</span> <span class="ow">and</span> <span class="n">next_link</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Pagination</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">items</span><span class="p">,</span>
                              <span class="n">constructor</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">,</span>
                              <span class="n">next_link</span><span class="o">=</span><span class="n">next_link</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">items</span></div>

<div class="viewcode-block" id="Folder.upload_file"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Folder.upload_file">[docs]</a>    <span class="k">def</span> <span class="nf">upload_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">,</span> <span class="n">item_name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">chunk_size</span><span class="o">=</span><span class="n">DEFAULT_UPLOAD_CHUNK_SIZE</span><span class="p">,</span>
                    <span class="n">upload_in_chunks</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">stream</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stream_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                    <span class="n">conflict_handling</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Uploads a file</span>

<span class="sd">        :param item: path to the item you want to upload</span>
<span class="sd">        :type item: str or Path</span>
<span class="sd">        :param item_name: name of the item on the server. None to use original name</span>
<span class="sd">        :type item_name: str or Path</span>
<span class="sd">        :param chunk_size: Only applies if file is bigger than 4MB or upload_in_chunks is True.</span>
<span class="sd">         Chunk size for uploads. Must be a multiple of 327.680 bytes</span>
<span class="sd">        :param upload_in_chunks: force the method to upload the file in chunks</span>
<span class="sd">        :param io.BufferedIOBase stream: (optional) an opened io object to read into.</span>
<span class="sd">         if set, the to_path and name will be ignored</span>
<span class="sd">        :param int stream_size: size of stream, required if using stream</span>
<span class="sd">        :param conflict_handling: How to handle conflicts.</span>
<span class="sd">         NOTE: works for chunk upload only (&gt;4MB or upload_in_chunks is True)</span>
<span class="sd">         None to use default (overwrite). Options: fail | replace | rename</span>
<span class="sd">        :type conflict_handling: str</span>
<span class="sd">        :return: uploaded file</span>
<span class="sd">        :rtype: DriveItem</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">stream</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">item</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Item must be a valid path to file&#39;</span><span class="p">)</span>
            <span class="n">item</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">item</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">Path</span><span class="p">)</span> <span class="k">else</span> <span class="n">item</span>

            <span class="k">if</span> <span class="ow">not</span> <span class="n">item</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Item must exist&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">item</span><span class="o">.</span><span class="n">is_file</span><span class="p">():</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Item must be a file&#39;</span><span class="p">)</span>

        <span class="n">file_size</span> <span class="o">=</span> <span class="p">(</span><span class="n">stream_size</span> <span class="k">if</span> <span class="n">stream_size</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">item</span><span class="o">.</span><span class="n">stat</span><span class="p">()</span><span class="o">.</span><span class="n">st_size</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">upload_in_chunks</span> <span class="ow">and</span> <span class="n">file_size</span> <span class="o">&lt;=</span> <span class="n">UPLOAD_SIZE_LIMIT_SIMPLE</span><span class="p">:</span>
            <span class="c1"># Simple Upload</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;simple_upload&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">,</span>
                                                            <span class="n">filename</span><span class="o">=</span><span class="n">quote</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">name</span> <span class="k">if</span> <span class="n">item_name</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">item_name</span><span class="p">)))</span>
            <span class="c1"># headers = {&#39;Content-type&#39;: &#39;text/plain&#39;}</span>
            <span class="n">headers</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;Content-type&#39;</span><span class="p">:</span> <span class="s1">&#39;application/octet-stream&#39;</span><span class="p">}</span>
            <span class="c1"># headers = None</span>
            <span class="k">if</span> <span class="n">stream</span><span class="p">:</span>
                <span class="n">data</span> <span class="o">=</span> <span class="n">stream</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">with</span> <span class="n">item</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">mode</span><span class="o">=</span><span class="s1">&#39;rb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
                    <span class="n">data</span> <span class="o">=</span> <span class="n">file</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>

            <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">headers</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">None</span>

            <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">(</span><span class="n">data</span><span class="p">)(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span>
                                          <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">data</span><span class="p">})</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Resumable Upload</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;create_upload_session&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">,</span> <span class="n">filename</span><span class="o">=</span><span class="n">quote</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">name</span> <span class="k">if</span> <span class="n">item_name</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">item_name</span><span class="p">)))</span>

            <span class="c1"># If not None, add conflict handling to request</span>
            <span class="n">file_data</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">if</span> <span class="n">conflict_handling</span><span class="p">:</span>
                <span class="n">file_data</span><span class="p">[</span><span class="s2">&quot;item&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;@microsoft.graph.conflictBehavior&quot;</span><span class="p">:</span> <span class="n">conflict_handling</span> <span class="p">}</span>

            <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">file_data</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">None</span>

            <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

            <span class="n">upload_url</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;uploadUrl&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
            <span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Resumable upload on url: </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">upload_url</span><span class="p">))</span>
            <span class="n">expiration_date</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;expirationDateTime&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">expiration_date</span><span class="p">:</span>
                <span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Expiration Date for this upload url is: </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">expiration_date</span><span class="p">))</span>
            <span class="k">if</span> <span class="n">upload_url</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Create upload session response without &#39;</span>
                          <span class="s1">&#39;upload_url for file </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
                <span class="k">return</span> <span class="kc">None</span>

            <span class="k">def</span> <span class="nf">write_stream</span><span class="p">(</span><span class="n">file</span><span class="p">):</span>
                <span class="n">current_bytes</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
                    <span class="n">data</span> <span class="o">=</span> <span class="n">file</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">chunk_size</span><span class="p">)</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">data</span><span class="p">:</span>
                        <span class="k">break</span>
                    <span class="n">transfer_bytes</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
                    <span class="n">headers</span> <span class="o">=</span> <span class="p">{</span>
                        <span class="s1">&#39;Content-type&#39;</span><span class="p">:</span> <span class="s1">&#39;application/octet-stream&#39;</span><span class="p">,</span>
                        <span class="s1">&#39;Content-Length&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)),</span>
                        <span class="s1">&#39;Content-Range&#39;</span><span class="p">:</span> <span class="s1">&#39;bytes </span><span class="si">{}</span><span class="s1">-</span><span class="si">{}</span><span class="s1">/</span><span class="si">{}</span><span class="s1">&#39;</span>
                                         <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">current_bytes</span><span class="p">,</span>
                                                   <span class="n">current_bytes</span> <span class="o">+</span>
                                                   <span class="n">transfer_bytes</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span>
                                                   <span class="n">file_size</span><span class="p">)</span>
                    <span class="p">}</span>
                    <span class="n">current_bytes</span> <span class="o">+=</span> <span class="n">transfer_bytes</span>

                    <span class="c1"># this request mut NOT send the authorization header.</span>
                    <span class="c1"># so we use a naive simple request.</span>
                    <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">naive_request</span><span class="p">(</span><span class="n">upload_url</span><span class="p">,</span> <span class="s1">&#39;PUT&#39;</span><span class="p">,</span>
                                                      <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span>
                                                      <span class="n">headers</span><span class="o">=</span><span class="n">headers</span><span class="p">)</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
                        <span class="k">return</span> <span class="kc">None</span>

                    <span class="k">if</span> <span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="o">!=</span> <span class="mi">202</span><span class="p">:</span>
                        <span class="c1"># file is completed</span>
                        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>
                        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">(</span><span class="n">data</span><span class="p">)(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">data</span><span class="p">})</span>
            <span class="k">if</span> <span class="n">stream</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">write_stream</span><span class="p">(</span><span class="n">stream</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">with</span> <span class="n">item</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">mode</span><span class="o">=</span><span class="s1">&#39;rb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
                    <span class="k">return</span> <span class="n">write_stream</span><span class="p">(</span><span class="n">file</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="Drive"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Drive">[docs]</a><span class="k">class</span> <span class="nc">Drive</span><span class="p">(</span><span class="n">ApiComponent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; A Drive representation.</span>
<span class="sd">    A Drive is a Container of Folders and Files and act as a root item &quot;&quot;&quot;</span>

    <span class="n">_endpoints</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;default_drive&#39;</span><span class="p">:</span> <span class="s1">&#39;/drive&#39;</span><span class="p">,</span>
        <span class="s1">&#39;get_drive&#39;</span><span class="p">:</span> <span class="s1">&#39;/drives/</span><span class="si">{id}</span><span class="s1">&#39;</span><span class="p">,</span>
        <span class="s1">&#39;get_root_item_default&#39;</span><span class="p">:</span> <span class="s1">&#39;/drive/root&#39;</span><span class="p">,</span>
        <span class="s1">&#39;get_root_item&#39;</span><span class="p">:</span> <span class="s1">&#39;/drives/</span><span class="si">{id}</span><span class="s1">/root&#39;</span><span class="p">,</span>
        <span class="s1">&#39;list_items_default&#39;</span><span class="p">:</span> <span class="s1">&#39;/drive/root/children&#39;</span><span class="p">,</span>
        <span class="s1">&#39;list_items&#39;</span><span class="p">:</span> <span class="s1">&#39;/drives/</span><span class="si">{id}</span><span class="s1">/root/children&#39;</span><span class="p">,</span>
        <span class="s1">&#39;get_item_default&#39;</span><span class="p">:</span> <span class="s1">&#39;/drive/items/</span><span class="si">{item_id}</span><span class="s1">&#39;</span><span class="p">,</span>
        <span class="s1">&#39;get_item&#39;</span><span class="p">:</span> <span class="s1">&#39;/drives/</span><span class="si">{id}</span><span class="s1">/items/</span><span class="si">{item_id}</span><span class="s1">&#39;</span><span class="p">,</span>
        <span class="s1">&#39;get_item_by_path_default&#39;</span><span class="p">:</span> <span class="s1">&#39;/drive/root:</span><span class="si">{item_path}</span><span class="s1">&#39;</span><span class="p">,</span>
        <span class="s1">&#39;get_item_by_path&#39;</span><span class="p">:</span> <span class="s1">&#39;/drives/</span><span class="si">{id}</span><span class="s1">/root:</span><span class="si">{item_path}</span><span class="s1">&#39;</span><span class="p">,</span>
        <span class="s1">&#39;recent_default&#39;</span><span class="p">:</span> <span class="s1">&#39;/drive/recent&#39;</span><span class="p">,</span>
        <span class="s1">&#39;recent&#39;</span><span class="p">:</span> <span class="s1">&#39;/drives/</span><span class="si">{id}</span><span class="s1">/recent&#39;</span><span class="p">,</span>
        <span class="s1">&#39;shared_with_me_default&#39;</span><span class="p">:</span> <span class="s1">&#39;/drive/sharedWithMe&#39;</span><span class="p">,</span>
        <span class="s1">&#39;shared_with_me&#39;</span><span class="p">:</span> <span class="s1">&#39;/drives/</span><span class="si">{id}</span><span class="s1">/sharedWithMe&#39;</span><span class="p">,</span>
        <span class="s1">&#39;get_special_default&#39;</span><span class="p">:</span> <span class="s1">&#39;/drive/special/</span><span class="si">{name}</span><span class="s1">&#39;</span><span class="p">,</span>
        <span class="s1">&#39;get_special&#39;</span><span class="p">:</span> <span class="s1">&#39;/drives/</span><span class="si">{id}</span><span class="s1">/special/</span><span class="si">{name}</span><span class="s1">&#39;</span><span class="p">,</span>
        <span class="s1">&#39;search_default&#39;</span><span class="p">:</span> <span class="s2">&quot;/drive/search(q=&#39;</span><span class="si">{search_text}</span><span class="s2">&#39;)&quot;</span><span class="p">,</span>
        <span class="s1">&#39;search&#39;</span><span class="p">:</span> <span class="s2">&quot;/drives/</span><span class="si">{id}</span><span class="s2">/search(q=&#39;</span><span class="si">{search_text}</span><span class="s2">&#39;)&quot;</span><span class="p">,</span>
    <span class="p">}</span>

<div class="viewcode-block" id="Drive.__init__"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Drive.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">con</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Create a drive representation</span>

<span class="sd">        :param parent: parent for this operation</span>
<span class="sd">        :type parent: Drive or Storage</span>
<span class="sd">        :param Connection con: connection to use if no parent specified</span>
<span class="sd">        :param Protocol protocol: protocol to use if no parent specified</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        :param str main_resource: use this resource instead of parent resource</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">parent</span> <span class="ow">and</span> <span class="n">con</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Need a parent or a connection but not both&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">con</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">con</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">con</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="n">parent</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">Drive</span><span class="p">)</span> <span class="k">else</span> <span class="kc">None</span>

        <span class="c1"># Choose the main_resource passed in kwargs over parent main_resource</span>
        <span class="n">main_resource</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">main_resource</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">main_resource</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">protocol</span><span class="o">=</span><span class="n">parent</span><span class="o">.</span><span class="n">protocol</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;protocol&#39;</span><span class="p">),</span>
            <span class="n">main_resource</span><span class="o">=</span><span class="n">main_resource</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_update_data</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">_update_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
        <span class="n">cloud_data</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">,</span> <span class="p">{})</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;id&#39;</span><span class="p">))</span>
        <span class="c1"># Fallback to manual drive</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">),</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">,</span>
                                                              <span class="s1">&#39;&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">description</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;description&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">drive_type</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;driveType&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">web_url</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;webUrl&#39;</span><span class="p">))</span>

        <span class="n">owner</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;owner&#39;</span><span class="p">),</span> <span class="p">{})</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;user&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">owner</span> <span class="o">=</span> <span class="n">Contact</span><span class="p">(</span><span class="n">con</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="p">,</span>
                             <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">owner</span><span class="p">})</span> <span class="k">if</span> <span class="n">owner</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">quota</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;quota&#39;</span><span class="p">))</span>  <span class="c1"># dict</span>

        <span class="n">created</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;createdDateTime&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">modified</span> <span class="o">=</span> <span class="n">cloud_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cc</span><span class="p">(</span><span class="s1">&#39;lastModifiedDateTime&#39;</span><span class="p">),</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">local_tz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">timezone</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">created</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="n">created</span><span class="p">)</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span><span class="n">local_tz</span><span class="p">)</span> <span class="k">if</span> <span class="n">created</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">modified</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="n">modified</span><span class="p">)</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span>
            <span class="n">local_tz</span><span class="p">)</span> <span class="k">if</span> <span class="n">modified</span> <span class="k">else</span> <span class="kc">None</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__repr__</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">owner</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">owner</span><span class="p">)</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">owner</span> <span class="k">else</span> <span class="s1">&#39;&#39;</span>
        <span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">or</span> <span class="s1">&#39;Default Drive&#39;</span>
        <span class="k">if</span> <span class="n">owner</span><span class="p">:</span>
            <span class="k">return</span> <span class="s1">&#39;Drive: </span><span class="si">{}</span><span class="s1"> (Owned by: </span><span class="si">{}</span><span class="s1">)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">owner</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="s1">&#39;Drive: </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">object_id</span>

<div class="viewcode-block" id="Drive.get_root_folder"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Drive.get_root_folder">[docs]</a>    <span class="k">def</span> <span class="nf">get_root_folder</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns the Root Folder of this drive</span>

<span class="sd">        :return: Root Folder</span>
<span class="sd">        :rtype: DriveItem</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="c1"># reference the current drive_id</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_root_item&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># we don&#39;t know the drive_id so go to the default drive</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_root_item_default&#39;</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">(</span><span class="n">data</span><span class="p">)(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span>
                                      <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">data</span><span class="p">})</span></div>

    <span class="k">def</span> <span class="nf">_base_get_list</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">order_by</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                       <span class="n">batch</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns a collection of drive items &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">limit</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">limit</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">max_top_value</span><span class="p">:</span>
            <span class="n">batch</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">max_top_value</span>

        <span class="n">params</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;$top&#39;</span><span class="p">:</span> <span class="n">batch</span> <span class="k">if</span> <span class="n">batch</span> <span class="k">else</span> <span class="n">limit</span><span class="p">}</span>

        <span class="k">if</span> <span class="n">order_by</span><span class="p">:</span>
            <span class="n">params</span><span class="p">[</span><span class="s1">&#39;$orderby&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">order_by</span>

        <span class="k">if</span> <span class="n">query</span><span class="p">:</span>
            <span class="c1"># if query.has_filters:</span>
            <span class="c1">#     warnings.warn(</span>
            <span class="c1">#         &#39;Filters are not allowed by the Api Provider &#39;</span>
            <span class="c1">#         &#39;in this method&#39;)</span>
            <span class="c1">#     query.clear_filters()</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">query</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
                <span class="n">params</span><span class="p">[</span><span class="s1">&#39;$filter&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">query</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">params</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">query</span><span class="o">.</span><span class="n">as_params</span><span class="p">())</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">iter</span><span class="p">(())</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="n">items</span> <span class="o">=</span> <span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">(</span><span class="n">item</span><span class="p">)(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">item</span><span class="p">})</span>
            <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;value&#39;</span><span class="p">,</span> <span class="p">[]))</span>
        <span class="n">next_link</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">NEXT_LINK_KEYWORD</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">batch</span> <span class="ow">and</span> <span class="n">next_link</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Pagination</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">items</span><span class="p">,</span>
                              <span class="n">constructor</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">,</span>
                              <span class="n">next_link</span><span class="o">=</span><span class="n">next_link</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">items</span>

<div class="viewcode-block" id="Drive.get_items"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Drive.get_items">[docs]</a>    <span class="k">def</span> <span class="nf">get_items</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">order_by</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">batch</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns a collection of drive items from the root folder</span>

<span class="sd">        :param int limit: max no. of items to get. Over 999 uses batch.</span>
<span class="sd">        :param query: applies a OData filter to the request</span>
<span class="sd">        :type query: Query or str</span>
<span class="sd">        :param order_by: orders the result set based on this condition</span>
<span class="sd">        :type order_by: Query or str</span>
<span class="sd">        :param int batch: batch size, retrieves items in</span>
<span class="sd">         batches allowing to retrieve more items than the limit.</span>
<span class="sd">        :return: items in this folder</span>
<span class="sd">        :rtype: generator of DriveItem or Pagination</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="c1"># reference the current drive_id</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;list_items&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># we don&#39;t know the drive_id so go to the default</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;list_items_default&#39;</span><span class="p">))</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_base_get_list</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="n">query</span><span class="p">,</span>
                                   <span class="n">order_by</span><span class="o">=</span><span class="n">order_by</span><span class="p">,</span> <span class="n">batch</span><span class="o">=</span><span class="n">batch</span><span class="p">)</span></div>

<div class="viewcode-block" id="Drive.get_child_folders"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Drive.get_child_folders">[docs]</a>    <span class="k">def</span> <span class="nf">get_child_folders</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">order_by</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">batch</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns all the folders inside this folder</span>

<span class="sd">        :param int limit: max no. of folders to get. Over 999 uses batch.</span>
<span class="sd">        :param query: applies a OData filter to the request</span>
<span class="sd">        :type query: Query or str</span>
<span class="sd">        :param order_by: orders the result set based on this condition</span>
<span class="sd">        :type order_by: Query or str</span>
<span class="sd">        :param int batch: batch size, retrieves items in</span>
<span class="sd">         batches allowing to retrieve more items than the limit.</span>
<span class="sd">        :return: folder items in this folder</span>
<span class="sd">        :rtype: generator of DriveItem or Pagination</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">query</span><span class="p">:</span>
            <span class="n">query</span> <span class="o">=</span> <span class="n">query</span><span class="o">.</span><span class="n">on_attribute</span><span class="p">(</span><span class="s1">&#39;folder&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">unequal</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">query</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">q</span><span class="p">(</span><span class="s1">&#39;folder&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">unequal</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_items</span><span class="p">(</span><span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="n">query</span><span class="p">,</span> <span class="n">order_by</span><span class="o">=</span><span class="n">order_by</span><span class="p">,</span> <span class="n">batch</span><span class="o">=</span><span class="n">batch</span><span class="p">)</span></div>

<div class="viewcode-block" id="Drive.get_recent"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Drive.get_recent">[docs]</a>    <span class="k">def</span> <span class="nf">get_recent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">order_by</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">batch</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns a collection of recently used DriveItems</span>

<span class="sd">        :param int limit: max no. of items to get. Over 999 uses batch.</span>
<span class="sd">        :param query: applies a OData filter to the request</span>
<span class="sd">        :type query: Query or str</span>
<span class="sd">        :param order_by: orders the result set based on this condition</span>
<span class="sd">        :type order_by: Query or str</span>
<span class="sd">        :param int batch: batch size, retrieves items in</span>
<span class="sd">         batches allowing to retrieve more items than the limit.</span>
<span class="sd">        :return: items in this folder</span>
<span class="sd">        :rtype: generator of DriveItem or Pagination</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="c1"># reference the current drive_id</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;recent&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># we don&#39;t know the drive_id so go to the default</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;recent_default&#39;</span><span class="p">))</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_base_get_list</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="n">query</span><span class="p">,</span>
                                   <span class="n">order_by</span><span class="o">=</span><span class="n">order_by</span><span class="p">,</span> <span class="n">batch</span><span class="o">=</span><span class="n">batch</span><span class="p">)</span></div>

<div class="viewcode-block" id="Drive.get_shared_with_me"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Drive.get_shared_with_me">[docs]</a>    <span class="k">def</span> <span class="nf">get_shared_with_me</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">order_by</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                           <span class="n">batch</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns a collection of DriveItems shared with me</span>

<span class="sd">        :param int limit: max no. of items to get. Over 999 uses batch.</span>
<span class="sd">        :param query: applies a OData filter to the request</span>
<span class="sd">        :type query: Query or str</span>
<span class="sd">        :param order_by: orders the result set based on this condition</span>
<span class="sd">        :type order_by: Query or str</span>
<span class="sd">        :param int batch: batch size, retrieves items in</span>
<span class="sd">         batches allowing to retrieve more items than the limit.</span>
<span class="sd">        :return: items in this folder</span>
<span class="sd">        :rtype: generator of DriveItem or Pagination</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="c1"># reference the current drive_id</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;shared_with_me&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># we don&#39;t know the drive_id so go to the default</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;shared_with_me_default&#39;</span><span class="p">))</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_base_get_list</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="n">query</span><span class="p">,</span>
                                   <span class="n">order_by</span><span class="o">=</span><span class="n">order_by</span><span class="p">,</span> <span class="n">batch</span><span class="o">=</span><span class="n">batch</span><span class="p">)</span></div>

<div class="viewcode-block" id="Drive.get_item"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Drive.get_item">[docs]</a>    <span class="k">def</span> <span class="nf">get_item</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item_id</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns a DriveItem by it&#39;s Id</span>

<span class="sd">        :return: one item</span>
<span class="sd">        :rtype: DriveItem</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="c1"># reference the current drive_id</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_item&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">,</span>
                                                       <span class="n">item_id</span><span class="o">=</span><span class="n">item_id</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># we don&#39;t know the drive_id so go to the default drive</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_item_default&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">item_id</span><span class="o">=</span><span class="n">item_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">(</span><span class="n">data</span><span class="p">)(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span>
                                      <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">data</span><span class="p">})</span></div>

<div class="viewcode-block" id="Drive.get_item_by_path"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Drive.get_item_by_path">[docs]</a>    <span class="k">def</span> <span class="nf">get_item_by_path</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item_path</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns a DriveItem by it&#39;s path: /path/to/file</span>
<span class="sd">        :return: one item</span>
<span class="sd">        :rtype: DriveItem</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="c1"># reference the current drive_id</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_item_by_path&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">,</span>
                                                               <span class="n">item_path</span><span class="o">=</span><span class="n">item_path</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># we don&#39;t know the drive_id so go to the default drive</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_item_by_path_default&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">item_path</span><span class="o">=</span><span class="n">item_path</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">(</span><span class="n">data</span><span class="p">)(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span>
                                      <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">data</span><span class="p">})</span></div>

<div class="viewcode-block" id="Drive.get_special_folder"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Drive.get_special_folder">[docs]</a>    <span class="k">def</span> <span class="nf">get_special_folder</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns the specified Special Folder</span>

<span class="sd">        :return: a special Folder</span>
<span class="sd">        :rtype: drive.Folder</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">name</span> <span class="o">=</span> <span class="n">name</span> <span class="k">if</span> \
            <span class="nb">isinstance</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">OneDriveWellKnowFolderNames</span><span class="p">)</span> \
            <span class="k">else</span> <span class="n">OneDriveWellKnowFolderNames</span><span class="p">(</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
        <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">value</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">:</span>
            <span class="c1"># reference the current drive_id</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_special&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">,</span>
                                                          <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># we don&#39;t know the drive_id so go to the default</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_special_default&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">(</span><span class="n">data</span><span class="p">)(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span>
                                      <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">data</span><span class="p">})</span></div>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">_classifier</span><span class="p">(</span><span class="n">item</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Subclass to change factory classes &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="s1">&#39;folder&#39;</span> <span class="ow">in</span> <span class="n">item</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Folder</span>
        <span class="k">elif</span> <span class="s1">&#39;image&#39;</span> <span class="ow">in</span> <span class="n">item</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Image</span>
        <span class="k">elif</span> <span class="s1">&#39;photo&#39;</span> <span class="ow">in</span> <span class="n">item</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Photo</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">File</span>

<div class="viewcode-block" id="Drive.refresh"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Drive.refresh">[docs]</a>    <span class="k">def</span> <span class="nf">refresh</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Updates this drive with data from the server</span>

<span class="sd">        :return: Success / Failure</span>
<span class="sd">        :rtype: bool</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;default_drive&#39;</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_drive&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="n">drive</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_update_data</span><span class="p">({</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">drive</span><span class="p">})</span>
        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="Drive.search"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Drive.search">[docs]</a>    <span class="k">def</span> <span class="nf">search</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search_text</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">query</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">order_by</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
               <span class="n">batch</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Search for DriveItems under this drive.</span>
<span class="sd">        Your app can search more broadly to include items shared with the</span>
<span class="sd">        current user.</span>

<span class="sd">        To broaden the search scope, use this search instead the Folder Search.</span>

<span class="sd">        The search API uses a search service under the covers, which requires</span>
<span class="sd">        indexing of content.</span>

<span class="sd">        As a result, there will be some time between creation of an</span>
<span class="sd">        item and when it will appear in search results.</span>

<span class="sd">        :param str search_text: The query text used to search for items.</span>
<span class="sd">         Values may be matched across several fields including filename,</span>
<span class="sd">         metadata, and file content.</span>
<span class="sd">        :param int limit: max no. of items to get. Over 999 uses batch.</span>
<span class="sd">        :param query: applies a OData filter to the request</span>
<span class="sd">        :type query: Query or str</span>
<span class="sd">        :param order_by: orders the result set based on this condition</span>
<span class="sd">        :type order_by: Query or str</span>
<span class="sd">        :param int batch: batch size, retrieves items in</span>
<span class="sd">         batches allowing to retrieve more items than the limit.</span>
<span class="sd">        :return: items in this folder matching search</span>
<span class="sd">        :rtype: generator of DriveItem or Pagination</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">search_text</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">search_text</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Provide a valid search_text&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">object_id</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;search_default&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">search_text</span><span class="o">=</span><span class="n">search_text</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;search&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">object_id</span><span class="p">,</span>
                                                     <span class="n">search_text</span><span class="o">=</span><span class="n">search_text</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">limit</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">limit</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">max_top_value</span><span class="p">:</span>
            <span class="n">batch</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="o">.</span><span class="n">max_top_value</span>

        <span class="n">params</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;$top&#39;</span><span class="p">:</span> <span class="n">batch</span> <span class="k">if</span> <span class="n">batch</span> <span class="k">else</span> <span class="n">limit</span><span class="p">}</span>

        <span class="k">if</span> <span class="n">order_by</span><span class="p">:</span>
            <span class="n">params</span><span class="p">[</span><span class="s1">&#39;$orderby&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">order_by</span>

        <span class="k">if</span> <span class="n">query</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">query</span><span class="o">.</span><span class="n">has_filters</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                    <span class="s1">&#39;Filters are not allowed by the Api Provider &#39;</span>
                    <span class="s1">&#39;in this method&#39;</span><span class="p">)</span>
                <span class="n">query</span><span class="o">.</span><span class="n">clear_filters</span><span class="p">()</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">query</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
                <span class="n">params</span><span class="p">[</span><span class="s1">&#39;$filter&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">query</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">params</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">query</span><span class="o">.</span><span class="n">as_params</span><span class="p">())</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">iter</span><span class="p">(())</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="n">items</span> <span class="o">=</span> <span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">(</span><span class="n">item</span><span class="p">)(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">item</span><span class="p">})</span>
            <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;value&#39;</span><span class="p">,</span> <span class="p">[]))</span>
        <span class="n">next_link</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">NEXT_LINK_KEYWORD</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">batch</span> <span class="ow">and</span> <span class="n">next_link</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Pagination</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">items</span><span class="p">,</span>
                              <span class="n">constructor</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_classifier</span><span class="p">,</span>
                              <span class="n">next_link</span><span class="o">=</span><span class="n">next_link</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">items</span></div></div>


<div class="viewcode-block" id="Storage"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Storage">[docs]</a><span class="k">class</span> <span class="nc">Storage</span><span class="p">(</span><span class="n">ApiComponent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Parent Class that holds drives &quot;&quot;&quot;</span>

    <span class="n">_endpoints</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;default_drive&#39;</span><span class="p">:</span> <span class="s1">&#39;/drive&#39;</span><span class="p">,</span>
        <span class="s1">&#39;get_drive&#39;</span><span class="p">:</span> <span class="s1">&#39;/drives/</span><span class="si">{id}</span><span class="s1">&#39;</span><span class="p">,</span>
        <span class="s1">&#39;list_drives&#39;</span><span class="p">:</span> <span class="s1">&#39;/drives&#39;</span><span class="p">,</span>
    <span class="p">}</span>
    <span class="n">drive_constructor</span> <span class="o">=</span> <span class="n">Drive</span>

<div class="viewcode-block" id="Storage.__init__"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Storage.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">con</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Create a storage representation</span>

<span class="sd">        :param parent: parent for this operation</span>
<span class="sd">        :type parent: Account</span>
<span class="sd">        :param Connection con: connection to use if no parent specified</span>
<span class="sd">        :param Protocol protocol: protocol to use if no parent specified</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        :param str main_resource: use this resource instead of parent resource</span>
<span class="sd">         (kwargs)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">parent</span> <span class="ow">and</span> <span class="n">con</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Need a parent or a connection but not both&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">con</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">con</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">con</span>

        <span class="c1"># Choose the main_resource passed in kwargs over parent main_resource</span>
        <span class="n">main_resource</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span>
            <span class="nb">getattr</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="s1">&#39;main_resource&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="kc">None</span><span class="p">)</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">protocol</span><span class="o">=</span><span class="n">parent</span><span class="o">.</span><span class="n">protocol</span> <span class="k">if</span> <span class="n">parent</span> <span class="k">else</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;protocol&#39;</span><span class="p">),</span>
            <span class="n">main_resource</span><span class="o">=</span><span class="n">main_resource</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__repr__</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;Storage for resource: </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">main_resource</span><span class="p">)</span>

<div class="viewcode-block" id="Storage.get_default_drive"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Storage.get_default_drive">[docs]</a>    <span class="k">def</span> <span class="nf">get_default_drive</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request_drive</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns a Drive instance</span>

<span class="sd">        :param request_drive: True will make an api call to retrieve the drive</span>
<span class="sd">         data</span>
<span class="sd">        :return: default One Drive</span>
<span class="sd">        :rtype: Drive</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">request_drive</span> <span class="ow">is</span> <span class="kc">False</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Drive</span><span class="p">(</span><span class="n">con</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="p">,</span>
                         <span class="n">main_resource</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">main_resource</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;Default Drive&#39;</span><span class="p">)</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;default_drive&#39;</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">drive</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">drive_constructor</span><span class="p">(</span><span class="n">con</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="p">,</span>
                                      <span class="n">main_resource</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">main_resource</span><span class="p">,</span>
                                      <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">drive</span><span class="p">})</span></div>

<div class="viewcode-block" id="Storage.get_drive"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Storage.get_drive">[docs]</a>    <span class="k">def</span> <span class="nf">get_drive</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">drive_id</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns a Drive instance</span>

<span class="sd">        :param drive_id: the drive_id to be retrieved</span>
<span class="sd">        :return: Drive for the id</span>
<span class="sd">        :rtype: Drive</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">drive_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;get_drive&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="n">drive_id</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="n">drive</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">drive_constructor</span><span class="p">(</span><span class="n">con</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">protocol</span><span class="p">,</span>
                                      <span class="n">main_resource</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">main_resource</span><span class="p">,</span>
                                      <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">drive</span><span class="p">})</span></div>

<div class="viewcode-block" id="Storage.get_drives"><a class="viewcode-back" href="../../api/drive.html#O365.drive.Storage.get_drives">[docs]</a>    <span class="k">def</span> <span class="nf">get_drives</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Returns a collection of drives&quot;&quot;&quot;</span>

        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_url</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_endpoints</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;list_drives&#39;</span><span class="p">))</span>

        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">con</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">response</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[]</span>

        <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>

        <span class="c1"># Everything received from cloud must be passed as self._cloud_data_key</span>
        <span class="n">drives</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">drive_constructor</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_cloud_data_key</span><span class="p">:</span> <span class="n">drive</span><span class="p">})</span> <span class="k">for</span>
                  <span class="n">drive</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;value&#39;</span><span class="p">,</span> <span class="p">[])]</span>

        <span class="k">return</span> <span class="n">drives</span></div></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, Narcolapser

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/language_data.js"></script>
    

  

  <script type="text/javascript" src="../../_static/js/theme.js"></script>

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>